package com.chenxi.controller;

import com.chenxi.common.controller.BaseController;
import com.chenxi.model.SysUser;
import com.chenxi.model.User;
import com.chenxi.service.ISysUserService;
import com.chenxi.service.UserServiceI;
import com.chenxi.util.PageData;
import com.chenxi.util.PageForm;
import com.chenxi.util.ResultJson;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(value = "/userApi/")
public class UserController extends BaseController {
    @Autowired
    private UserServiceI userService;

    @Autowired
    private ISysUserService sysUserService;

    @RequestMapping(value = "page")
    public ResultJson page(HttpServletRequest request, PageForm pageForm){
        Map<String,String[]> params = request.getParameterMap();

        Map<String, Object> map = Maps.newHashMap();
        //map.put("draw",draw);
        params.forEach((key,v) ->{

        });
        ResultJson rj = super.getSuccess();
        PageData<SysUser> pageData = sysUserService.page(pageForm);
        rj.setData(pageData);
        return rj;
    }

    @RequestMapping(value = "page1",method = RequestMethod.POST)
    public PageData<User> getPage(HttpServletRequest request){
        Map<String,String[]> params = request.getParameterMap();
        int draw = Integer.parseInt(request.getParameter("draw"));

        PageData<User> pageData = new PageData();
        pageData.setData(userService.find(null));
        pageData.setDraw(draw);
        pageData.setRecordsFiltered(1L);
        pageData.setRecordsTotal(1L);
        return pageData;
    }

}

